package leecode;

 class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}
public class leetcode4 {
    //第一题
    public String replaceSpace(String s) {
        StringBuilder s1=new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i)==' '){
                s1.append("%20");
            }else {
                s1.append(s.charAt(i));
            }
        }
        s=s1.toString();
        return s;
    }
    //第二题
    public String reverseLeftWords(String s, int n) {
        StringBuilder s1=new StringBuilder(s);
        int i=0;
        while (n>0){
            s1.append(s1.append(i));
            s1.deleteCharAt(i);
            n--;
        }
        return s1.toString();
    }
    // 2/100
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode head=l1;
        int i=0;
        int a=0;
        while (l1!=null||l2!=null){
            if(l1==null){
                a=l2.val+i;
            }else if(l2==null){
                a=l1.val+i;
            }else { a=l1.val+l2.val+i;}
            i=0;
            if(a>=10){
                i=1;
                a%=10;
            }
            l1.val=a;
            l2=l2.next;
            l1=l1.next;
        }
        return head;
    }
}
